package com.bawei.es.conf;

import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@Configuration
public class EsConfiguration {

//    @Value("${spring.data.elasticsearch.cluster-name}")
//    public String clusterName;
//    @Value("${spring.data.elasticsearch.cluster-nodes}")
//    public String clusterNodes;
//    @Bean
//    public RestHighLevelClient restHighLevelClient(){
//        System.out.println(clusterNodes);
//        String[] split = clusterNodes.split(":");
//        if (split.length != 2){
//            System.out.println(split);
//            throw new RuntimeException("ElasticSearch ip配置"+clusterNodes);
//        }
//
//        Integer integer = null;
//
//        try {
//            integer = Integer.valueOf(split[1]);
//        } catch (Exception e) {
//            throw new RuntimeException("ElasticSearch ip配置异常"+clusterNodes);
//        }
//        System.out.println(integer);
//
//        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(
//                RestClient.builder(new HttpHost(split[0],integer,"http"))
//        );
//        return restHighLevelClient;
//    }


}
